package com.cbd.sa_tocken;

import cn.dev33.satoken.stp.StpInterface;
import com.cbd.service.IUserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author: CBD
 * @Date: 2024/11/22 11:44
 * @Description:自定义权限验证接口实现类
 */
@Component
@Slf4j
public class StpInterfaceImpl implements StpInterface {
    @Resource
    private IUserService useService;

    /**
     * 获取用户的角色和权限列表
     * @param loginId 账号ID(登录写入的状态信息) StpUtil.login(id)
     * @param loginType 账号的体系标识，比如：用户名、手机号、邮箱等
     * @return
     */
    @Override
    public List<String> getPermissionList(Object loginId, String loginType) {
        String username = (String) loginId;
        log.info("loginId：{}, loginType：{}", loginId, loginType);
        List<String> permissionList = useService.getPermissions(username);
        log.info("permissionList：{}", permissionList);
        return permissionList;
    }

    /**
     * 获取用户的角色列表
     * @param loginId 账号ID(登录写入的状态信息) StpUtil.login(id)
     * @param loginType 账号的体系标识，比如：用户名、邮箱等
     * @return
     */

    @Override
    public List<String> getRoleList(Object loginId, String loginType) {
        String username = (String) loginId;
        log.info("loginId：{}, loginType：{}", loginId, loginType);
        List<String> roleList = useService.getRoles(username);
        log.info("roleList：{}", roleList);
        return roleList;
    }
}
